/**
 * @author https://vue-admin-beautiful.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },

  {
    path: '/business',
    component: Layout,
    redirect: '/business/list',
    alwaysShow: true, // will always show the root menu
    name: 'MerchantManagement',
    meta: {
      title: '商家管理',
      icon: 'store',
      roles: ['admin', 'user'], // you can set roles in root nav
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/business/list/index'),
        name: 'MerchantList',
        meta: { title: '商家列表' },
      },
      {
        path: 'add',
        component: () => import('@/views/business/add/index'),
        name: 'AddMerchant',
        meta: { title: '商家入驻' },
      },
      {
        path: 'edit',
        component: () => import('@/views/business/edit/index'),
        name: 'EditMerchant',
        hidden: true,
        meta: { title: '修改商家' },
      },
    ],
  },
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/list',
    alwaysShow: true, // will always show the root menu
    name: 'GoodsManagement',
    meta: {
      title: '商品管理',
      icon: 'shopping-bag',
      roles: ['admin', 'user'], // you can set roles in root nav
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/goods/list/index'),
        name: 'GoodsList',
        meta: { title: '商品列表' },
      },
      {
        path: 'add',
        component: () => import('@/views/goods/add/index'),
        name: 'AddGoods',
        meta: { title: '发布商品' },
      },
      {
        path: 'edit',
        component: () => import('@/views/goods/edit/index'),
        name: 'EditGoods',
        hidden: true,
        meta: { title: '修改商品' },
      },
    ],
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    alwaysShow: true, // will always show the root menu
    name: 'OrderManagement',
    meta: {
      title: '订单管理',
      icon: 'clipboard',
      roles: ['admin', 'user'], // you can set roles in root nav
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/order/list/index'),
        name: 'OrderList',
        meta: { title: '订单列表' },
      },
    ],
  },
  {
    path: '/specification',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/specification/index'),
        name: 'specification',
        meta: { title: '商品规格管理', icon: 'hockey-puck' },
      },
    ],
  },
  {
    path: '/UserManagement',
    component: Layout,
    // // alwaysShow: true, // will always show the root menu
    // name: "UserManagement",
    // meta: {
    //   title: "用户管理",
    //   icon: "peoples",
    //   roles: ["admin", "user"], // you can set roles in root nav
    // },
    // redirect: '/index',
    children: [
      {
        path: 'list',
        component: () => import('@/views/userManagement/index'),
        name: 'UserManagement',
        meta: { title: '用户管理', icon: 'users-cog', permissions: 'admin' },
        roles: ['admin'],
      },
    ],
  },
  {
    path: '/personalCenter',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/personalCenter/index'),
        name: 'PersonalCenter',
        meta: { title: '个人中心', icon: 'user' },
      },
    ],
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
